package com.king.designpatterns.hybriddesignpattern.hybriddesignpattern.factorystrategypatterns;

/**
 * 自由消费扣款策略
 *
 * @author king
 * @date 2021-06-13 23:14
 */
public class FreeDeduction implements IDeduction{
    @Override
    public boolean exec(Card card, Trade trade) {
        // 获取交易金额
        double m = trade.getAmount();
        // 获取ID卡中的自由金额
        double f = card.getFreeMoney();
        // 如果交易金额比自由金额大，交易失败
        if (m > f){
            return false;
        }else{
            // 从自由金额中扣除
            card.setFreeMoney(f - m);
            return true;
        }
    }
}
